define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>确定是否提交？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });

    var _vm = Init.initVue({
        data : {
            list : [],
            cur : 1,
            all : 0,
            schFlag : false,
            search : {
                user_name : "",
                status_is : "",
                group_id : ""
            },
            grouplist : []
        },
        methods: {
            reSearch : function() {
                this.schFlag = true;
                this.getData(1);
            },
            reset : function() {
                this.schFlag = false;
                this.search.user_name = "";
                this.search.group_id = "";
                this.search.status_is = "";
            },
            getData : function(n) {
                _vm.search.page = n;
                _vm.search.num = 10;

                METHOD.loading.show();
                METHOD.ajax("admin/get_list", _vm.search).done(function(json){
                    METHOD.loading.hide();
                    _vm.list = json.data;
                    _vm.all = json.page.pages;
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            operate : function(id,status) {
                var status_is;

                if (status == 1) {
                    _Dialog.changeCfg({content : "<p>禁用后，该帐户将不能登录</p>"});
                    status_is = 2;
                } else if (status == 2) {
                    _Dialog.changeCfg({content : "<p>启用后，该帐户可重新登录</p>"});
                    status_is = 1;
                };
                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("admin/operate_status", { id: id, status_is: status_is }, {type:"post"}).done(function(json){
                            METHOD.loading.hide();
                            _vm.getData(_vm.cur);
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }

                    this.hideUI();
                });
            },
            reset : function(id) {
                _Dialog.changeCfg({content : "<p>是否确定重置该帐户的密码为123456？</p>"});

                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax("admin/reset_pwd", { id:id }, {type:"post"}).done(function(){
                            METHOD.loading.hide();
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }

                    this.hideUI();
                });
            }
        }
    });

    METHOD.loading.show();
    METHOD.ajax("admin/group/get_list", { page:1,num:100 }).done(function(json){
        METHOD.loading.hide();
        _vm.grouplist = json.data;
    }).fail(function(){
        METHOD.loading.hide();
    });

    _vm.getData(1);

});

